package cn.edu.scujcc.dpl.ui.home;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;

import com.bumptech.glide.Glide;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;
import java.util.List;

import cn.edu.scujcc.dpl.R;
import cn.edu.scujcc.dpl.playerActivity;

public class HomeFragment extends Fragment {
    private HomeViewModel homeViewModel;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        homeViewModel =
                ViewModelProviders.of(this).get(HomeViewModel.class);
        View root = inflater.inflate(R.layout.fragment_home, container, false);
        ImageView btn =  root.findViewById(R.id.player1);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v){
                Intent it = new Intent();
                it.setClass(getActivity(), playerActivity.class);
                getActivity().startActivity(it);
            }
        });
        return root;
    }

//    List<Integer> imageUrlData;
//    List<String> contentData;
//    Banner myBanner;
//
//    @Nullable
//    @Override
//        public View onCreateView(@NonNull LayoutInflater inflater,
//                                 ViewGroup container, Bundle savedInstanceState) {
//        View view = inflater.inflate(R.layout.fragment_home, container, false);
//        myBanner = view.findViewById(R.id.banner);
//        initBanner();
//        return view;
//    }
//    private void initBanner() {
//        imageUrlData = new ArrayList<>();
//        contentData = new ArrayList<>();
//        imageUrlData.add(R.drawable.a);
//        imageUrlData.add(R.drawable.b);
//        imageUrlData.add(R.drawable.c);
//        imageUrlData.add(R.drawable.d);
//        myBanner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE);
//        myBanner.setImageLoader(new MyLoader());
//        myBanner.setImages(imageUrlData);
//        myBanner.setBannerTitles(contentData);
//        myBanner.setBannerAnimation(Transformer.Default);
//        //切换频率
//        myBanner.setDelayTime(2000);
//        //自动启动
//        myBanner.isAutoPlay(true);
//        //位置设置
//        myBanner.setIndicatorGravity(BannerConfig.CENTER);
//        //开始运行
//        myBanner.start();
//    }
//
//
//    private class MyLoader extends ImageLoader {
//        @Override
//        public void displayImage(Context context, Object path, ImageView imageView) {
//            Glide.with(getActivity()).load(path).into(imageView);
//        }
//    }



//    private HomeViewModel homeViewModel;
//    homeViewModel =
//                    ViewModelProviders.of(this).get(HomeViewModel.class);
//            View root = inflater.inflate(R.layout.fragment_home, container, false);
//            final TextView textView = root.findViewById(R.id.textView);
//            homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
//                @Override
//                public void onChanged(@Nullable String s) {
//
//                    textView.setText(s);
//                }
//            });
//            return root;
        }





